/*
    @file kern_step.cl
    @author Claus Wimmer
    @date 2014-07-19

    Project: secondspace-2
    Licence: LGPL (Lesser GPL)
*/

/*
    Step kernel execution function called by OPENCL.
*/
__kernel void kern_step(
        __global float *_spaceData, // Space data.
        __global int *_spaceBits,   // User bits to mark space pixels.
        __global uchar *_imgData,   // Image area.
        __global uint *_step,       // Each calculation increases the step count by one.
        __global int *_slider,      // User slider to adjust the contrast.
        __global uint *_mouse,      // User's mouse position.
        __global uint *_modus,      // User's radio buttons to switch between three rendering modes.
        const uint _rows,           // Number of pixel rows in space.
        const uint _cols,           // Number of pixel columns in space.
        const uint _layers,         // Number of pixel layers in space.
        const uint _varsiz) {       // Number of variables within one pixel.
    // Do not go behind the border.
    if(1 < ROW && 1 < COL && _rows - 1 > ROW && _cols - 1 > COL) {
        // Buffer step one.
        if(1 == _step[0] % 2) {
            SELF(E) += (LEFT(H) - RIGHT(H)  ) * SELF(VX);
            SELF(E) += (UP(H)   - DOWN(H)   ) * SELF(VY);
        }
        // Buffer step two.
        if(0 == _step[0] % 2) {
            SELF(H) += (LEFT(E) - RIGHT(E)  ) * SELF(VX);
            SELF(H) += (UP(E)   - DOWN(E)   ) * SELF(VY);
        }
    }
    // End space step, render the image.
    if(0 == _step[0] % 2){
        show(_spaceData, _spaceBits, _imgData, _slider, _modus,_rows, _cols, _varsiz);
    }
}
